import { parse } from 'yaml'
const path = require('path')
const fs = require('fs')


/**
 * 获取项目运行环境
 */

export const getEnv = () => {
  return process.env.RUN_ENV
}

/**
 * 读取项目配置
 */
export const getConfig = () => {
  const environment = getEnv()
  const yamlPath = path.join(process.cwd(), `./config/.${environment}.yaml`)
  const file = fs.readFileSync(yamlPath, 'utf-8')
  const config = parse(file)
  return config
}

/**
 * 读取key配置
 */
export const getKeys = () => {
  const privateKey = fs.readFileSync(path.join(process.cwd(), "./config/key/private/key"))
  const publicKey = fs.readFileSync(path.join(process.cwd(), "./config/key/public/key"))
  return {
    JWT: {
      privateKey,
      publicKey
    }
  }
}